package com.jumper.property.comparer.starter.mybatis;

import com.jumper.property.comparer.core.support.result.LogEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BusOptLogMapper {

    /**
     * 插入日志
     */
    @Insert("insert into ${tableName} (gmt_created, gmt_modified, action, data_key, log_value, opt_user_id, opt_user_name) values (#{insert.gmtCreated},#{insert.gmtModified},#{insert.action},#{insert.dataKey},#{insert.logValue},#{insert.optUserId},#{insert.optUserName})")
    void insert(@Param("tableName") String tableName, @Param("insert") LogEntity optLog);

    @Select("select count(*) from ${tableName} where data_key = #{dataKey}")
    int count(@Param("tableName") String tableName, @Param("dataKey") String dataKey);

    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "gmtCreated", column = "gmt_created"),
            @Result(property = "gmtModified", column = "gmt_modified"),
            @Result(property = "action", column = "action"),
            @Result(property = "dataKey", column = "data_key"),
            @Result(property = "logValue", column = "log_value"),
            @Result(property = "optUserId", column = "opt_user_id"),
            @Result(property = "optUserName", column = "opt_user_name")
    })
    @Select("select t1.id , t1.gmt_created, t1.gmt_modified, t1.action, t1.data_key, t1.log_value, t1.opt_user_id, t1.opt_user_name from ${tableName} t1 where t1.data_key = #{dataKey} order by t1.gmt_created desc limit #{offset},#{pageSize}")
    List<LogEntity> select(@Param("tableName") String tableName, @Param("dataKey") String dataKey, @Param("offset") int offset, @Param("pageSize") int pageSize);
}
